<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>双向数据绑定</title>
  </head>
  <body>
    <input type="text" />
    <span></span>
    <script>
      let obj = { content: "" };
      let input = document.querySelector("input");
      let span = document.querySelector("span");

      Object.defineProperty(obj, "content", {
        get() {},
        set(newVal) {
          input.value = newVal;
          span.innerText = newVal;
        },
      });

      input.addEventListener("keyup", (e) => {
        obj.content = e.target.value;
      });
    </script>
  </body>
</html>
